# -*- coding: utf-8 -*-

from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()

from sqlalchemy import Column, DateTime, String, BigInteger, Float, Integer
from datetime import datetime

class MarketDepthItem(Base):
    __tablename__ = 'marketdepth'
    
    id          = Column(BigInteger, primary_key=True)
    contractid  = Column(Integer)
    position    = Column(Integer)
    operation   = Column(Integer)
    side        = Column(Integer)
    price       = Column(Float)
    size        = Column(Float)
    insertdate  = Column(DateTime)
    inserttime  = Column(DateTime)
    
    def __init__(self, ibmsg):
        if ibmsg != None:        
            self.contractid  = ibmsg.tickerId
            self.position    = ibmsg.position
            self.operation   = ibmsg.operation
            self.side        = ibmsg.side
            self.price       = ibmsg.price
            self.size        = ibmsg.size
            self.insertdate  = datetime.utcnow().date()
            self.inserttime  = datetime.utcnow()


    
    def __repr__(self):
        return "<MarketDepthItem(id='%s', position='%s', side='%s, price='%s', size='%s')>" % (self.contractid, self.position, self.side, self.price, self.size)        